package org.base;

import javax.inject.Named;
import javax.faces.view.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;

@Named(value = "nomenclaturaCatastralController")
@ViewScoped
public class NomenclaturaCatastralController extends AbstractController<NomenclaturaCatastral> {

    @Inject
    private BarrioController barrioCollectionController;
    @Inject
    private EstadoNomenclaturaController estadoNomenclaturaIdController;

    public NomenclaturaCatastralController() {
        // Inform the Abstract parent controller of the concrete NomenclaturaCatastral?cap_first Entity
        super(NomenclaturaCatastral.class);
    }

    /**
     * Resets the "selected" attribute of any parent Entity controllers.
     */
    public void resetParents() {
        estadoNomenclaturaIdController.setSelected(null);
    }

    /**
     * Sets the "items" attribute with a collection of Barrio entities that are
     * retrieved from NomenclaturaCatastral?cap_first and returns the navigation
     * outcome.
     *
     * @return navigation outcome for Barrio page
     */
    public String navigateBarrioCollection() {
        if (this.getSelected() != null) {
            FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("Barrio_items", this.getSelected().getBarrioCollection());
        }
        return "/barrio/index";
    }

    /**
     * Sets the "selected" attribute of the EstadoNomenclatura controller in
     * order to display its data in a dialog. This is reusing existing the
     * existing View dialog.
     *
     * @param event Event object for the widget that triggered an action
     */
    public void prepareEstadoNomenclaturaId(ActionEvent event) {
        if (this.getSelected() != null && estadoNomenclaturaIdController.getSelected() == null) {
            estadoNomenclaturaIdController.setSelected(this.getSelected().getEstadoNomenclaturaId());
        }
    }
}
